home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 007a / 899track.zip / 899PICK.PRO < prev    next >
Text File  |  1990-03-06  |  9KB  |  220 lines

  1. project "899"
  2. include "899glob.pro"
  3.  
  4. % 899PICK.PRO -- Choices window for this system
  5. % USES UNKNOWN NUMBER OF WINDOWS STARTING AT WINDOW NUMBER 30
  6. % GLOBAL PREDICATES IN THIS FILE::
  7. %        show_get
  8.  
  9.  
  10. DOMAINS
  11.   intlist = INTEGER*
  12.  
  13. DATABASE - wlib
  14.   wdef(INTEGER)                                 % Window definition (nondeterm) 
  15.   determ wcount(INTEGER)                        % A count of the number of windows
  16.   determ wsize(INTEGER,INTEGER,INTEGER,INTEGER) % Resulting window(s) size of Rows,Columns,Ent Rows,Ent Columns
  17.   determ wtit(STRING)                           % Common Title
  18.   edef(INTEGER,INTEGER,INTEGER,gs)
  19.     % The above is edef(WindowNumber,Xcoord,Ycoord,StringAtThatLocation)
  20.  
  21. PREDICATES
  22.   calcsize(INTEGER,INTEGER)   % Calculate the seze of the windows given max size of an entity and number of entities
  23.   ars(INTEGER,INTEGER)        % Given number of Row Entities, calculate the number of rows per window
  24.   calcwindows                 % Calculate the number of windows (size extracted)
  25.   asw(INTEGER,INTEGER)        % Asserts the windoe definition (wdef) in the correct order
  26.   build_edef(gsList,INTEGER)  % Buld the database edef definitions for all the given list (Number of windows extracted)
  27.   ef(gsList,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER) % Actually builds the edef.
  28.   build_windows               % Make all the windows diplayable
  29.   disp_ents(INTEGER)          % Does the diplaying of entities
  30.   dispell_info                % Get rid of everything
  31.   memberI(INTEGER,intlist)    % member on integers
  32.   chz1(INTEGER,INTEGER,INTEGER,INTEGER,gs)
  33.   chz2(key,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,gs)
  34.   pick_edit_dispatch(key,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER)
  35.   reg_title(STRING)           % Registers title to display
  36.  
  37. CLAUSES
  38.   memberI(X,[X|_]).
  39.   memberI(X,[_|T]) :-
  40.     memberI(X,T).
  41.  
  42.   show_get(ListIn,StrOut,TitleToShow) :-     /* HERE IT IS!!!!!!! */
  43.     makewindow(OldWnum,_,_,_,_,_,_,_),
  44.     maxlen(ListIn,0,MaxStringLength),  /* First get the longest string length */
  45.     listlen(ListIn,NumberOfItems),     /* Then get the number of items */
  46.     calcsize(MaxStringLength,NumberOfItems),
  47.     calcwindows,
  48.     build_edef(ListIn,MaxStringLength),
  49.     reg_title(TitleToShow),
  50.     not(build_windows),
  51.     shiftwindow(30),
  52.     cursor(0,0),
  53.     StepX = 1,  StepY = MaxStringLength + 1,
  54.     chz1(0,0,StepX,StepY,StrOut),
  55.     dispell_info,
  56.     shiftwindow(OldWnum).  % And return to the calling window
  57.  
  58.   calcsize(MaxStringLength,TotalEntCount) :-
  59.     ((MaxStringLength+1) * 2) <= 78, !,  % See if at least 2 can fit in largest window possible!!
  60.     % At this point we automatically choose the largest window possible and calcuate the rest
  61.     ColumnsOfEnts = 78 div (MaxStringLength+1),
  62.     RowsOfEnts = (TotalEntCount div ColumnsOfEnts) + 1,
  63.     ars(RowsOfEnts,RowsPerWindow), % Get the number of rows necesary for each window
  64.     ColumnsPerWindow = 80,
  65.     assert(wsize(RowsPerWindow,ColumnsPerWindow,RowsOfEnts,ColumnsOfEnts),wlib).
  66.   calcsize(MaxStringLength,TotalEntCount) :- % Here we can only have one column of entities
  67.     ColumnsOfEnts = 1,
  68.     ColumnsPerWindow = MaxStringLength+3,
  69.     RowsOfEnts = TotalEntCount,
  70.     ars(RowsOfEnts,RowsPerWindow),
  71.     assert(wsize(RowsPerWindow,ColumnsPerWindow,RowsOfEnts,ColumnsOfEnts),wlib).
  72.  
  73.   ars(RowsOfEnts,RowsPerWindow) :-
  74.     RowsOfEnts < 23, !, % If Less than one screenfull then...
  75.     RowsPerWindow = RowsOfEnts+2.
  76.   ars(_,25).  % Otherwise, max out the window to full screen
  77.  
  78.   calcwindows :-
  79.     wsize(RowsPerWindow,_,RowsOfChoices,_),
  80.     RowsOfChoices <= (RowsPerWindow-2), !, % If RowsOfChoices is <= rowsPerWindow, then there is only one window
  81.     assert(wcount(1),wlib),
  82.     asw(30,30). % And just put this single window in our database
  83.   calcwindows :- % Here, we require more than one window to display all the choices
  84.     wsize(RowsPerWindow,_,RowsOfChoices,_),
  85.     NumberOfWindows = (RowsOfChoices div (RowsPerWindow-2)) + 1,
  86.     assert(wcount(NumberOfWindows),wlib), % Place the number of windows here
  87.     MaxWindowNumber = 30 + NumberOfWindows - 1,
  88.     asw(MaxWindowNumber,30).
  89.  
  90.   asw(N,N) :- !, asserta(wdef(N),wlib).
  91.   asw(Curr,Ending) :-
  92.     asserta(wdef(Curr),wlib),
  93.     NewC = Curr - 1,
  94.     asw(NewC,Ending).
  95.  
  96.   build_edef(ListOfEnts,MaxStringLength) :-  % Build thew list
  97.     wsize(RowsPerWindow,_,_,ColumnsOfEnts), % Get this definition from database
  98.     FieldWidth = MaxStringLength + 1,
  99.     MaxRowNum = (RowsPerWindow-2) - 1,  % 2 dor the frames and take in account the numbering scheme
  100.     ef(ListOfEnts,ColumnsOfEnts,0,0,0,MaxRowNum,30,FieldWidth).  % Do it!!!
  101.  
  102.   ef([],_,_,_,_,_,_,_) :- !. /* Finished building the definition */
  103.   ef([Str|L],EntCol,CurrEntCol,CurrY,CurrEntRow,MaxRow,CurrWindow,FieldWidth) :-
  104.     CurrEntCol < EntCol, !, % Make sure we don't go to far to the right logically
  105.     assert(edef(CurrWindow,CurrEntRow,CurrY,Str),wlib),
  106.     NewY = CurrY + FieldWidth,
  107.     NewEntCol = CurrEntCol + 1,
  108.     ef(L,EntCol,NewEntCol,NewY,CurrEntRow,MaxRow,CurrWindow,FieldWidth).
  109.   ef(Lister,EntCol,_,_,CurrEntRow,MaxRow,CurrWindow,FieldWidth) :-
  110.     % At this point, the y column has reached it's max, so we do the row increment
  111.     NewRow = CurrEntRow + 1,
  112.     NewRow <= MaxRow, !, % Make sure we don't go off the bottom of the window
  113.     NewY = 0, NewEntCol = 0,
  114.     ef(Lister,EntCol,NewEntCol,NewY,NewRow,MaxRow,CurrWindow,FieldWidth).
  115.   ef(Lister,EntCol,_,_,_,MaxRow,CurrWindow,FieldWidth) :-
  116.     % at this point we now increment the window numbers
  117.     NewWindow = CurrWindow + 1,
  118.     NewRow = 0,
  119.     NewEntCol = 0,
  120.     NewY = 0,
  121.     ef(Lister,EntCol,NewEntCol,NewY,NewRow,MaxRow,NewWindow,FieldWidth).
  122.  
  123.   build_windows :-  % This clause will fail
  124.     wcount(MaxPageCount),
  125.     str_int(MxStr,MaxPageCount), % Make a string of it 
  126.     wtit(Temp1),  % Get the Title part
  127.     Temp2 = " (Page ",
  128.     Temp3 = " of ",
  129.     Temp4 = ")",
  130.     wdef(Win), /* Grab a window definiton */
  131.       wsize(NumRows,NumColumns,_,_), /* And snag this */
  132.       CpageInt = Win - 29,
  133.       str_int(CurrPageNum,CpageInt),
  134.       fronttoken(K1,Temp1,Temp2), fronttoken(K2,K1,CurrPageNum),
  135.       fronttoken(K3,K2,Temp3), fronttoken(K4,K3,MxStr),
  136.       fronttoken(Title,K4,Temp4),
  137.       makewindow(Win,6,15,Title,0,0,NumRows,NumColumns,clear_window,center_title,single_line_frame),
  138.     disp_ents(Win).
  139.  
  140.   disp_ents(CurW) :-     % This clause will fail
  141.     edef(CurW,R,C,Str),   % Grab a string definition
  142.       cursor(R,C),
  143.       write(Str),
  144.     fail.
  145.  
  146.   dispell_info :-
  147.     wdef(Gimmie),
  148.       gotowindow(Gimmie),
  149.       removewindow,
  150.     fail.
  151.   dispell_info :- % Now kill all our database
  152.     retractall(_,wlib).
  153.  
  154.   chz1(CurrX,CurrY,StepX,StepY,RetString) :-
  155.     makewindow(CurrW,Att,_,_,_,_,_,_),
  156.     getbacktrack(Btop),
  157.     edef(CurrW,CurrX,CurrY,StrHere),
  158.     cutbacktrack(Btop),
  159.     str_len(StrHere,Stlen),
  160.     inverse(Att,InvAtt),
  161.     field_attr(CurrX,CurrY,Stlen,InvAtt),  % Set the attribute
  162.     getkey(Choice,[cr,esc,up,down,right,left,pgup,pgdn]),
  163.     field_attr(CurrX,CurrY,Stlen,Att),  % Reset the attribute
  164.     pick_edit_dispatch(Choice,StepX,StepY,CurrW,CurrX,CurrY),  % Do a dispatch
  165.     chz2(Choice,CurrX,CurrY,StepX,StepY,CurrW,RetString).
  166.  
  167.   chz2(esc,_,_,_,_,_,"") :- !.
  168.   chz2(cr,CurrX,CurrY,_,_,CurrW,RetSpec) :- !,
  169.     edef(CurrW,CurrX,CurrY,RetSpec).
  170.   chz2(up,_,_,StepX,StepY,_,RetSpec) :- !,
  171.     cursor(NewX,NewY),
  172.     chz1(NewX,NewY,StepX,StepY,RetSpec).
  173.   chz2(down,_,_,StepX,StepY,_,RetSpec) :- !,
  174.     cursor(NewX,NewY),
  175.     chz1(NewX,NewY,StepX,StepY,RetSpec).
  176.   chz2(right,_,_,StepX,StepY,_,RetSpec) :- !,
  177.     cursor(NewX,NewY),
  178.     chz1(NewX,NewY,StepX,StepY,RetSpec).
  179.   chz2(left,_,_,StepX,StepY,_,RetSpec) :- !,
  180.     cursor(NewX,NewY),
  181.     chz1(NewX,NewY,StepX,StepY,RetSpec).
  182.   chz2(pgup,_,_,StepX,StepY,CurrW,RetSpec) :-
  183.     NewPage = CurrW - 1,
  184.     wdef(NewPage),  /* May exist... may not */
  185.     !,
  186.     shiftwindow(NewPage), cursor(0,0),
  187.     chz1(0,0,StepX,StepY,RetSpec).
  188.   chz2(pgdn,_,_,StepX,StepY,CurrW,RetSpec) :-
  189.     NewPage = CurrW + 1,
  190.     wdef(NewPage),  /* May Exist ... May not */
  191.     !,
  192.     shiftwindow(NewPage), cursor(0,0),
  193.     chz1(0,0,StepX,StepY,RetSpec).
  194.   chz2(_,CurrX,CurrY,StepX,StepY,_,RetSpec) :-
  195.     chz1(CurrX,CurrY,StepX,StepY,RetSpec).
  196.  
  197.   pick_edit_dispatch(up,StepX,_,CurrW,CurrX,CurrY) :-
  198.     TargetX = CurrX - StepX,
  199.     edef(CurrW,TargetX,CurrY,_), !, /* If this exists, then move there */
  200.     cursor(TargetX,CurrY).
  201.   pick_edit_dispatch(down,StepX,_,CurrW,CurrX,CurrY) :-
  202.     TargetX = CurrX + StepX,
  203.     edef(CurrW,TargetX,CurrY,_), !, /* If this exists, then move */
  204.     cursor(TargetX,CurrY).
  205.   pick_edit_dispatch(right,_,StepY,CurrW,CurrX,CurrY) :-
  206.     TargetY = CurrY + StepY,
  207.     edef(CurrW,CurrX,TargetY,_), !,
  208.     cursor(CurrX,TargetY).
  209.   pick_edit_dispatch(left,_,StepY,CurrW,CurrX,CurrY) :-
  210.     TargetY = CurrY - StepY,
  211.     edef(CurrW,CurrX,TargetY,_), !,
  212.     cursor(CurrX,TargetY).
  213.   pick_edit_dispatch(_,_,_,_,_,_).  /* Don't do anything */
  214.  
  215.   reg_title("") :- !, % On a null string, use default title
  216.       assertz(wtit("Use cursors,\17\217 selects,ESC=EXIT"),wlib).
  217.   reg_title(NewTitle) :-
  218.       assertz(wtit(NewTitle),wlib).
  219.  
  220.